package listeners;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

import beans.Panier;

/**
 * Application Lifecycle Listener implementation class MySessionListener
 *
 */
public class MySessionListener implements HttpSessionListener {

    /**
     * Default constructor. 
     */
    public MySessionListener() {
        // TODO Auto-generated constructor stub
    }

	/**
     * @see HttpSessionListener#sessionCreated(HttpSessionEvent)
     */
    public void sessionCreated(HttpSessionEvent sessionEvent) {
    	/**
		 * création du panier à l'ouverture de la session
		 */
    	System.out.println("session créée");
		Panier monPanier = new Panier();
		sessionEvent.getSession().setAttribute("panier", monPanier);
    }

	/**
     * @see HttpSessionListener#sessionDestroyed(HttpSessionEvent)
     */
    public void sessionDestroyed(HttpSessionEvent sessionEvent) {
        // TODO Auto-generated method stub
    	//il faudrait sauvegarder panier en cours en bdd)
    	System.out.println("session détruite...");
    	
    }
	
}
